package cn.schoolwow.quickdao.module.operation.flow;

import cn.schoolwow.quickdao.domain.QuickDAOConfig;
import cn.schoolwow.quickdao.domain.entity.Entity;
import cn.schoolwow.quickdao.module.database.dml.instance.service.TruncateTableFlow;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;

public class ClearEntityTableFlow implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        QuickDAOConfig quickDAOConfig = flowContext.checkInstanceData(QuickDAOConfig.class);

        for(Entity entity:quickDAOConfig.databaseContext.entityMap.values()){
            flowContext.startFlow(new TruncateTableFlow())
                    .putCurrentCompositeFlowData("tableName", entity.tableName)
                    .execute();
        }
    }

    @Override
    public String name() {
        return "清空实体类表";
    }
}
